# -*- coding: utf-8 -*-
"""
Created on Fri Nov 17 15:41:48 2017

@author: JanComputer
"""
from .Parser import Parser
from bs4 import BeautifulSoup
from urllib.parse import urljoin
import re
class ParserYouQuBa(Parser):
    def paserHtml(self):
        if self.data:
            data=self.data
            text=data.get('text')
            netloc=data.get('netloc')
            taga=None
            next_url=None
            if text is not None:
                bs=BeautifulSoup(text,'lxml')
                taga=bs.select('.jokebox > p')
                next_url=bs.find('a',string=re.compile('下一页'))
                if next_url is not None:
                    try:
                        next_url=urljoin(netloc,'wangwen/'+next_url['href'])
                    except Exception as e:
                        self.logger.exception('next_url error:%s'%netloc)
                return {'jokes':taga,'next_url':next_url}
